from dvadmin.utils.serializers import CustomModelSerializer
from .models import Material, StockRecord

class MaterialSerializer(CustomModelSerializer):
    """原材料序列化器"""
    class Meta:
        model = Material
        fields = "__all__"

class MaterialCreateUpdateSerializer(CustomModelSerializer):
    """原材料创建/更新序列化器"""
    class Meta:
        model = Material
        fields = '__all__'

class StockRecordSerializer(CustomModelSerializer):
    """库存记录序列化器"""
    class Meta:
        model = StockRecord
        fields = "__all__"
        depth = 1  # 展开外键字段

class StockRecordCreateUpdateSerializer(CustomModelSerializer):
    """库存记录创建/更新序列化器"""
    class Meta:
        model = StockRecord
        fields = '__all__'
        extra_kwargs = {
            'before_quantity': {'required': False},  # 设置为非必填
            'after_quantity': {'required': False},   # 设置为非必填
        } 